<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('工种管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <!--图表：柱形图、饼状图、折线图-->
      <a-button @click="showRadarChart" type="primary"><a-icon type="radar-chart" />柱状图</a-button>
      <a-button @click="showPieChart" type="primary"><a-icon type="pie-chart" />饼状图</a-button>
      <a-button @click="showAreaChart" type="primary"><a-icon type="area-chart" />曲线图</a-button>
    </div>

    <div>
      <a-modal
        title="当前工具箱工具"
        :visible="visible"
        :confirm-loading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
      >
        <j-form-container>
          <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
<!--            <a-form-model-item label="工具箱id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolboxId">-->
<!--              <a-input  v-model="dataValue.id" placeholder="请输入工具箱id"  ></a-input>-->
<!--            </a-form-model-item>-->
            <a-form-model-item label="工具" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <span v-if="this.toolboxResult == null || this.toolboxResult.length===0">
                <a-input disabled defaultValue="暂无数据"  style="width: 100%;height: 20px"></a-input>
              </span>
              <span v-else>
                <a-input disabled style="width: 50%" v-for="(val,key) in toolboxResult" :key="key" :value="val"></a-input>
              </span>
<!--              <a-select style="width: 100%;margin-top: 20px" v-model="dataValue.toolAdminId">-->
<!--                <a-select-option  v-for="(val,key) in toolboxResult" :key="key" :value="val">-->
<!--                  {{val}}-->
<!--                </a-select-option>-->
<!--              </a-select>-->
            </a-form-model-item>
          </a-form-model>
        </j-form-container>
      </a-modal>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <div class="ant-alert ant-alert-info" style="text-align: center;border: 0;background-color: #cccccc">
        <span>工具箱信息</span>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">


        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="showModal(record.id)">工具箱信息</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <toolbox-modal ref="modalForm" @ok="modalFormOk">

    </toolbox-modal><tool-toolbox-list style="width: 103%;margin-left: -25px;margin-right: -80px"></tool-toolbox-list>
    <toolbox-chart-modal ref="modalRadarChart" mark="radar" :selection-rows="selectionRows" :chartTitle="title.radarTitle"></toolbox-chart-modal>
    <toolbox-chart-modal ref="modalPieChart" mark="pie" :selection-rows="selectionRows" :chartTitle="title.pieTitle"></toolbox-chart-modal>
    <toolbox-chart-modal ref="modalAreaChart" mark="area" :selection-rows="selectionRows" :chartTitle="title.areaTitle"></toolbox-chart-modal>
    <toolbox-modal ref="modalForm" @ok="modalFormOk"></toolbox-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ToolboxModal from './modules/ToolboxModal'
  import { postAction,getAction } from '@api/manage'
  import ToolToolboxList from '@views/modules/tooltoolbox/ToolToolboxList'
  import ToolboxChartModal from './chart/ToolboxChartModal'

  export default {
    name: 'ToolboxList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ToolToolboxList,
      ToolboxModal,
      ToolboxChartModal
    },
    data () {
      return {
        disableValue:true,
        toolboxResult:[],
        dataValue:{id:'',toolAdminId:''},
        model:{},
        visible: false,
        confirmLoading: false,
        description: '工种管理管理页面',
        // 表头
        columns: [

          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'工具箱名称',
            align:"center",
            dataIndex: 'str1'
          },
          {
            title:'工具箱ID',
            align:"center",
            dataIndex: 'str2'
          },
          {
            title:'工种',
            align:"center",
            dataIndex: 'str3'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        title:{
            radarTitle:"工具箱使用信息柱状图数据分析",
            pieTitle:"工具箱使用信息饼图数据分析",
            areaTitle:"工具箱使用信息折线走势分析"
         },
        url: {
          list: "/toolbox/toolbox/list",
          delete: "/toolbox/toolbox/delete",
          deleteBatch: "/toolbox/toolbox/deleteBatch",
          exportXlsUrl: "/toolbox/toolbox/exportXls",
          importExcelUrl: "toolbox/toolbox/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        validatorRules: {
          toolboxId: [
            { required: true, message: '请输入工具箱id!'},
          ],
          toolAdminId: [
            { required: true, message: '请输入工具id!'},
          ],
        },
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'toolboxName',text:'工具箱名称',dictCode:''})
        fieldList.push({type:'string',value:'toolboxNum',text:'工具箱ID',dictCode:''})
        this.superFieldList = fieldList
      },
      showModal(id) {
        console.log("id="+id)
        this.dataValue.id = id;
        this.visible = true;
        getAction('/tooltoolbox/toolToolbox/toolList',this.dataValue)
        .then(res=>{
          this.toolboxResult = res.result;
          console.log("success:"+this.toolboxResult)
        }).catch(res=>{
          console.log("error:"+res)
        })
      },
      handleOk(e) {
        this.confirmLoading = true;
        setTimeout(() => {
          this.visible = false;
          this.confirmLoading = false;
        }, 2000);
      },
      handleCancel(e) {
        console.log('Clicked cancel button');
        this.visible = false;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>